package xml.sax;

import java.beans.XMLEncoder;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class XML2Object {
    public static void main(String[] args) {
        //Object ->xml
        //
        List<Book> list=new ArrayList<>();
        for(int i=1;i<=10;i++){
            Book b=new Book(i,"java"+i+"大全",100,5,"很好的一本书");
            list.add(b);
        }
        try {
            XMLEncoder xe=new XMLEncoder(new FileOutputStream("mybook.xml"));
            xe.writeObject(list);//保存对象
            xe.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
